home *** CD-ROM | disk | FTP | other *** search
- /*
- Make thng.c
-
- C code to turn a resource file into a 'thng', or a system extension containing a
- component.
-
- This is not really needed for older versions of Sym/Think C/C++; however, for version
- 8.x, code resources are built and added to the projects resource file. The project
- resource file must then have it's type and creator changed into whatever it should
- be, i.e. an INIT or a 'thng'.
-
- This tiny little drop application will do that automagically. ;-)
-
- */
-
- #include <Files.h>
- #include <SegLoad.h>
-
- #define kThingType 'thng'
-
- typedef OSType** OSTypeHdl;
-
- void InitToolbox(void);
- OSErr TickleParent(FSSpecPtr spec);
-
- void InitToolbox(void){
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- FlushEvents(everyEvent,0);
- TEInit();
- InitDialogs(0L);
- InitCursor();
- }
-
- void main(void){
- short message,count;
- register short loop;
- AppFile theFile;
- FSSpec spec;
- short rnum;
- short vref;
- long dirid,junk;
- OSTypeHdl bndl;
- Handle h;
- OSErr err;
- OSType sig;
- FInfo info;
-
- InitToolbox();
-
- CountAppFiles(&message,&count);
-
- if (count==0) // no files to process, return
- return;
-
- if (message==appOpen){
- // got the open file message, ignore the print message
- for (loop=1;loop<=count;loop++){
- // for each file given to us...
- GetAppFiles(loop,&theFile);
-
- // make an FSSpec from the file
- err=GetWDInfo(theFile.vRefNum,&vref,&dirid,&junk);
- if (err!=noErr)
- continue; // can't do this file, try another
-
- FSMakeFSSpec(vref,dirid,theFile.fName,&spec);
-
- // have the file, open the resource fork
- rnum=FSpOpenResFile(&spec,fsRdPerm);
- if (rnum==0)
- continue; // can't do this file, try another
-
- // after open, get the handle for the 'BNDL' resource
- h=Get1IndResource('BNDL',1);
- if (h==(Handle)0){
- CloseResFile(rnum);
- continue;
- }
-
- // detach and close the res file
- DetachResource(h);
- CloseResFile(rnum);
-
- // extract the signature from the 'BNDL' resource
- bndl=(OSTypeHdl)h;
- sig=**bndl;
- DisposeHandle(h);
-
- // set the new type and creator
- err=FSpGetFInfo(&spec,&info);
- if (err!=noErr)
- continue;
-
- info.fdType=kThingType;
- info.fdCreator=sig;
-
- FSpSetFInfo(&spec,&info);
-
- TickleParent(&spec);
- }
- }
- }
-
- OSErr TickleParent(FSSpecPtr spec){
- CInfoPBRec pb;
- OSErr err;
-
- // Fill in the parm block
- pb.dirInfo.ioCompletion = 0;
- pb.dirInfo.ioNamePtr = 0;
- pb.dirInfo.ioVRefNum = spec->vRefNum;
- pb.dirInfo.ioFDirIndex = -1; // get info based on the DirID
- pb.dirInfo.ioDrDirID = spec->parID;
-
- // get the dir info
- err=PBGetCatInfoSync(&pb);
-
- if (err!=noErr)
- return err;
-
- // get the new modification date
- GetDateTime( &pb.dirInfo.ioDrMdDat );
-
- // set dir is modified
- err=PBSetCatInfoSync( &pb );
-
- return err;
- }
-